# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2021年12月07日
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

aa = r'../source/000001.xlsx'
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
pd.set_option('display.max_columns', 1000)
pd.set_option('display.width', 1000)

df = pd.read_excel(aa, parse_dates=['date'])
# df['date'] = pd.to_datetime(df['date'])

df = df.set_index('date')
df = df[['close']]
df['20天'] = np.round(df['close'].rolling(window=20, center=False).mean(), 2)
df['50天'] = np.round(df['close'].rolling(window=50, center=False).mean(), 2)
df['200天'] = np.round(df['close'].rolling(window=200, center=False).mean(), 2)

plt.rcParams['font.sans-serif'] = ['SimHei']  # 解决中文乱码
df.plot(secondary_y=['收盘价', '20', '50', '200'], grid=True)
plt.legend(('收盘价', '20天', '50天', '200天'), loc='upper right')
plt.show()

print(df.head())
